<?php

namespace app\admin\controller\csmwj;

use think\Db;
use Exception;
use PDOException;
use think\exception\ValidateException;
use addons\csmwj\library\xcore\xcore\base\XcABackend;
use addons\csmwj\library\xcore\xcore\utils\XcRequestUtils;
use addons\csmwj\library\xcore\xcore\utils\XcAdminTabUtils;

/**
 * 问卷
 *
 * @icon fa fa-circle-o
 */
class Papertheme extends XcABackend
{

    /**
     * Papertheme模型对象
     * @var \app\admin\model\csmwj\Papertheme
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\csmwj\Papertheme;
        $this->view->assign("localesList", $this->model->getLocalesList());
        $this->view->assign("cfghasdatelimitList", $this->model->getCfghasdatelimitList());
        $this->view->assign("cfghastimelimitList", $this->model->getCfghastimelimitList());
        $this->view->assign("cfgdisplayscoreList", $this->model->getCfgdisplayscoreList());
        $this->view->assign("statusList", $this->model->getStatusList());
        $this->view->assign("themebannertypeList", $this->model->getThemebannertypeList());
        $this->view->assign("themetitleshowList", $this->model->getThemetitleshowList());
        $this->view->assign("themequestionnoshowList", $this->model->getThemequestionnoshowList());


        // csmwj:设置页面tabs
        $id = XcRequestUtils::param("ids");
        XcAdminTabUtils::append_control_initialize('paper', $id, __CLASS__, $this->view);
    }

    public function edit($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error(__('No Results were found'));
        }
        $adminIds = $this->getDataLimitAdminIds();
        if (is_array($adminIds)) {
            if (!in_array($row[$this->dataLimitField], $adminIds)) {
                $this->error(__('You have no permission'));
            }
        }
        if ($this->request->isPost()) {
            $params = $this->request->post("row/a");
            if ($params) {
                $params = $this->preExcludeFields($params);
                $result = false;
                Db::startTrans();
                try {
                    //是否采用模型验证
                    if ($this->modelValidate) {
                        $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
                        $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
                        $row->validateFailException(true)->validate($validate);
                    }
                    $result = $row->allowField(true)->save($params);
                    Db::commit();
                } catch (ValidateException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (PDOException $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                } catch (Exception $e) {
                    Db::rollback();
                    $this->error($e->getMessage());
                }
                if ($result !== false) {
                    $this->success();
                } else {
                    $this->error(__('No rows were updated'));
                }
            }
            $this->error(__('Parameter %s can not be empty', ''));
        }
        $this->assignconfig("rooturl", $_SERVER["REQUEST_SCHEME"] . "://" . $_SERVER["SERVER_NAME"]);
        $this->view->assign("row", $row);
        return $this->view->fetch();
    }


    //列表
    public function index()
    {
        return;
    }
    //添加
    public function add()
    {
        return;
    }

    //删除
    public function del($ids = null)
    {
        return;
    }
    //回收站列表
    public function recyclebin()
    {
        return;
    }
    //回收站(真实删除或清空)
    public function destroy($ids = null)
    {
        return;
    }
    //回收站还原
    public function restore($ids = null)
    {
        return;
    }
    //批量操作(修改状态)
    public function multi($ids = null)
    {
        return;
    }
}
